package com.superc.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
import com.superc.client.notebook.NotebookEditDialog;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class Mysuperwebstore implements EntryPoint {
	/**
	 * The message displayed to the user when the server cannot be reached or
	 * returns an error.
	 */
	private static final String SERVER_ERROR = "An error occurred while "
			+ "attempting to contact the server. Please check your network "
			+ "connection and try again.";

	public void onModuleLoad() {
		RootPanel panel=RootPanel.get("nameFieldContainer");
		
		Grid grid = new Grid(1, 3);
		panel.add(grid, 0, 0);
		grid.setSize("100%", "100%");
		
		Image imgFavorite = new Image("image/favorites.png");
		grid.setWidget(0, 0, imgFavorite); 
		
		Image imgNotebook = new Image("image/notebook.png");
		grid.setWidget(0, 1, imgNotebook);
		
		Image imgConfig = new Image("image/config.png");
		grid.setWidget(0, 2, imgConfig);
		grid.getCellFormatter().setVerticalAlignment(0, 0, HasVerticalAlignment.ALIGN_MIDDLE);
		grid.getCellFormatter().setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
		grid.getCellFormatter().setHorizontalAlignment(0, 1, HasHorizontalAlignment.ALIGN_CENTER);
		grid.getCellFormatter().setVerticalAlignment(0, 1, HasVerticalAlignment.ALIGN_MIDDLE);
		grid.getCellFormatter().setHorizontalAlignment(0, 2, HasHorizontalAlignment.ALIGN_CENTER);
		grid.getCellFormatter().setVerticalAlignment(0, 2, HasVerticalAlignment.ALIGN_MIDDLE);
		
		imgFavorite.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				openWindow("http://www.google.com.hk/ig?t=0");
				openWindow("http://www.nytimes.com/");
				openWindow("http://www.ifeng.com/");
				openWindow("http://www.pconline.com.cn/");
				openWindow("http://www.csdn.net/");
				openWindow("http://www.xinhuanet.com/");
				openWindow("http://www.tianya.cn/");
				openWindow("http://sports.sina.com.cn/");
				openWindow("http://www.ccw.com.cn/");
				openWindow("http://www.onlinedown.net/index.htm");
				openWindow("http://www.ea3w.com/");
			}});
		
		imgNotebook.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				NotebookEditDialog dialog=new NotebookEditDialog();
				dialog.center();
				dialog.show();
			}});
		
		imgConfig.addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) {
				Window.open("http://mysuperwebstore.appspot.com/","_blank",null);
			}});
		
	}
		
	/**
	 * 本地打开网页
	 */
	public static native void openWindow(String url) /*-{ 
	    window.open(url);
	}-*/;
	
	
}
